package com.metro.demo.web.converter;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.metro.demo.web.controller.BaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

public class CustomLongConverter extends StdSerializer<Long> {
    protected Logger log = LoggerFactory.getLogger(CustomLongConverter.class);
    public CustomLongConverter() {
        super(Long.class);
    }
    @Override
    public void serialize(Long value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException {
        if (value.toString().length() > 12) {
            gen.writeString(value.toString());
        } else {
            gen.writeNumber(value);
        }
    }
}